package main

// 注意import 需要引入对应数据库驱动
import (
	"context"
	"fmt"
	_ "gitee.com/chunanyong/dm"
	"gitee.com/chunanyong/zorm"
	"wsgt/features"
)

//_ "github.com/mattn/go-oci8"  //连接oracle的包
//_ "github.com/mattn/go-adodb" //sql server  mssql
//_ "github.com/go-sql-driver/mysql" //mysql
//_ github.com/bmizerany/pq // postgres
//_ github.com/mattn/go-sqlite3 //sqlite3
// dm8 官方有驱动包 source/divers/go 推荐使用 "gitee.com/chunanyong/dm" 走go mod
// kingbase 可以使用odbc连接
/**
	注意：
 	只需要修改  dbs参数 与 驱动包即可 其他无需操作 ！！！
*/

var dbs = features.DBS{
	//	DSN:            "root:password01!@tcp(127.0.0.1:3306)/manage?charset=utf8&parseTime=true",  //mysql DSN
	DSN:                "dm://TEST:password01!@127.0.0.1:5236", //DM  DSN
	DBName:             "TEST",                                 //数据库名称
	DiverName:          "dm",                                   //这里切换为连接的数据库类型 例如 :oracle,dm,mysql
	PackageName:        "x",                                    // package包名
	ServicePackageName: "x2",                                   //service package包名
	StructImportName:   "wsgt/code/x",                          //service下 import结构体路径
}

var db *zorm.DBDao
var ctx = context.Background()

func main() {

	switch dbs.DBType {
	case "mysql":
		features.IsMysql(ctx, &dbs)
	case "dm":
		features.IsDm(ctx, &dbs)
	case "oracle":
		features.IsDm(ctx, &dbs) //虽然没测　但是理论上可行哈哈哈　可以走一样的方法
		//case "postgres":
		//	features.IsPostgres()
		//case "sqlserver":
		//	features.IsSqlserver()
		//case "sqlite3":
		//	features.IsSqlite3()
		//case "kingbase":
		//	features.IsKingbase()
	}

}

func init() {
	var err error
	dbConfig := &zorm.DataSourceConfig{
		DSN:                   dbs.DSN,
		DriverName:            dbs.DiverName,
		DBType:                dbs.DiverName,
		PrintSQL:              true,
		MaxOpenConns:          0,
		MaxIdleConns:          0,
		ConnMaxLifetimeSecond: 0,
		DefaultTxOptions:      nil,
	}

	db, err = zorm.NewDBDao(dbConfig)

	if err != nil {
		fmt.Errorf("数据库连接异常", err)
		panic(err)
	}
}
